$(window).load(function(){
	//顶部渐变轮播图
	var currIndex = 0,
		nextIndex = 1,
		lunImg = $(".news-topimg");
		lunTip = $(".news-tip div");

	var timer = setInterval(function(){
		lunImg.eq(currIndex).fadeOut();
		lunImg.eq(nextIndex).fadeIn();
		lunImg.eq(nextIndex).attr("display","block").siblings().removeAttr("display","block");
		lunTip.eq(nextIndex).addClass("cur").siblings().removeClass("cur");
		currIndex = nextIndex;
		nextIndex++;
		if(nextIndex == lunImg.length){
			nextIndex = 0;
		}
	},5000)

	//滚动加载
	function loadText(data,i){
		if(data[i].Image == ""){
			var listImg = "images/news_listimg.png";
		}else{
			var listImg = "http://ydche.com/media/mcimg/"+data[i].Image;
		}
		var text = $('<div class="news-art"><div class="news-title">'+
			'<h6 articleid="'+data[i].id+'">'+
		data[i].title+'</h6><p>'+
		data[i].summary+'</p></div><div class="news-image">'+
		'<img src='+listImg+' /></div></div>');
		text.appendTo($(".list"));
	}

	var pageNum = 1;
	// dropload
	$('.content').dropload({
		scrollArea : window,
		loadDownFn : function(me){
			$.ajax({
				type: "GET",
				async: true,
				url: wxAddress+"/weixin/subject/list?row=5&page="+pageNum,
				success: function(data) {
					if(data.code == "0000"){
						var data =data.data;
						if(data.length == 0){// 判断出现没有数据的情况
							me.lock();// 锁定
							me.noData();// 无数据
						}
						if(pageNum == 1){
							for(var i=0;i<3;i++){
								loadText(data,i);
							}
							var moreTxet = $('<p class="news-other"><img src="images/news-other.png" /><span>其他广场文章</span></p>');
							moreTxet.appendTo($(".list"));
							for(var i=3;i<data.length;i++){
								loadText(data,i);
							}
						}else{
							for(var i=0;i<data.length;i++){
								loadText(data,i);
							}
						}
						// 点击跳转
						$(".news-title").on("click","h6",function(){
							var articleID = $(this).attr("articleid");
							window.location.href = "newsart.html?articleID="+articleID;
						})
						me.resetload();//加载完成，重置
						pageNum++;
					}else{
						console.log(data.msg);
					}
				},
				error: function(xhr, type){
					console.log("Ajax error!");
					me.noData();
					// 即使加载出错，也得重置
					me.resetload();
				}
			})
		}
	});
})